<template>
    <el-dialog :title="info.SNAME + '的学生信息'" :visible="dialogVisible" @update:visible="updateDialogVisible" width="500px">
      <el-form :model="info" class="form-item-data" label-width="100px">
        <el-form-item label="学生学号">{{ info.SNO }}</el-form-item>
        <el-form-item label="学生姓名">{{ info.SNAME }}</el-form-item>
        <el-form-item label="学生性别">{{ info.SSEX }}</el-form-item>
        <el-form-item label="宿舍号">{{ dormConvert(info)}}</el-form-item>
        <el-form-item label="专业">{{ info.MAJOR_NAME }}</el-form-item>
        <el-form-item label="居住状态">{{ dormState(info) }}</el-form-item>
      </el-form>
    </el-dialog>
  </template>
  <script>
  import { ref, computed } from 'vue';
  import { resideStatusMap, studyStatusMap } from '@/utils/staticData';
  
  export default {
    name: 'StudentDetail',
    props: {
      info: Object,
      visible: Boolean,
    },
    mounted() {
    // console.log('BulkAssignDorm is mounted')
    // console.log('visible:', this.visible)
  },
    setup(props) {
      const dialogVisible = ref(false);
  
      const updateDialogVisible = (value) => {
        dialogVisible.value = value;
        if (!value) {
          // dialog关闭时的处理逻辑
        }
      };
  
      const studentSex = computed(() => {
        return props.info.student_sex === 1 ? '男' : props.info.student_sex === 2 ? '女' : '';
      });
  
      const resideStatus = computed(() => resideStatusMap.get(props.info.reside_status));
      const studyStatus = computed(() => studyStatusMap.get(props.info.study_status));
  
      const dormConvert=(row)=> {
        if (row.DROMSTATE === 1) {
          return row.DORM_ID
        }
        if (row.DROMSTATE === -1) {
          return "未入寝"
        }
        if (row.DROMSTATE === 2) {
          return "已退寝"
        }
      };

      const dormState = (row) => {
        if (!row || row.DROMSTATE === undefined || row.DROMSTATE === null) {
          return "未知状态";
        }
        
        if (row.DROMSTATE === 1) {
          return "已入寝";
        }
        
        if (row.DROMSTATE === -1) {
          return "未入寝";
        }
        
        if (row.DROMSTATE === 2) {
          return "已退寝";
        }
        
        return "未知状态"; // Handle any other cases not covered above
      };

      const convertToDate = (timestamp) => {
        const date = new Date(timestamp);
        const year = date.getFullYear();
        const month = (date.getMonth() + 1).toString().padStart(2, '0');
        const day = date.getDate().toString().padStart(2, '0');
        return `${year}-${month}-${day}`;
      };
  
      return {
        dialogVisible,
        updateDialogVisible,
        studentSex,
        resideStatus,
        studyStatus,
        dormState,
        dormConvert,
        convertToDate,
      };
    },
  };
  </script>